package de.tum.in.eist.poll.client;

import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.RootPanel;

/***
 * class for abstraction of operations related to the menu in the upper-right-corner
 */
public class MenuWidget {
	public MenuWidget(){
		final Hyperlink studentLink = new Hyperlink("Student", "studentLogin");
		final Hyperlink lecturerLink = new Hyperlink("Lecturer", "lecturerLogin");
		RootPanel.get("nav").add(studentLink);
		RootPanel.get("nav").add(lecturerLink);
	}
	void initMode(String mode){
		RootPanel.get("secnav").clear();
		/*final Hyperlink resultLink = new Hyperlink("Results", "viewResults");
		RootPanel.get("secnav").add(resultLink);*/
		RootPanel.get("nav").getElement().getElementsByTagName("a").getItem((mode.equals("student"))? 0 : 1).addClassName("active");
		RootPanel.get("nav").getElement().getElementsByTagName("a").getItem((mode.equals("student"))? 1 : 0).removeClassName("active");
	}
	void initLecturerMenu(String mode){
		initMode("lecturer");
		final Hyperlink viewResultsLink = new Hyperlink("Results", "viewResults");
		final Hyperlink manageIDsLink = new Hyperlink("Student IDs", "manageIDs");
		final Hyperlink manageLecturesLink = new Hyperlink("Lectures", "manageLectures");
		RootPanel.get("secnav").add(viewResultsLink);
		RootPanel.get("secnav").add(manageIDsLink);
		RootPanel.get("secnav").add(manageLecturesLink);
		for(int i = 0; i < RootPanel.get("secnav").getElement().getElementsByTagName("a").getLength(); i++){
			if(RootPanel.get("secnav").getElement().getElementsByTagName("a").getItem(i).getAttribute("href").equals("#"+mode)){
				RootPanel.get("secnav").getElement().getElementsByTagName("a").getItem(i).addClassName("active");
			}else{
				RootPanel.get("secnav").getElement().getElementsByTagName("a").getItem(i).removeClassName("active");
			}
		}
	}
}
